package com.ycx.furns.dao.impl;

import com.ycx.furns.dao.BasicDAO;
import com.ycx.furns.dao.OrderItemDAO;
import com.ycx.furns.entity.OrderItem;

import java.util.List;

public class OrderItemDAOImpl extends BasicDAO<OrderItem> implements OrderItemDAO {
    @Override
    public int saveOrderItem(OrderItem orderItem) {
        String sql = "INSERT INTO `order_item`(`name`,`price`, `count`, `total_price`, order_id) " +
                "VALUES( ?,  ?, ?, ?, ?)";
        return update(sql, orderItem.getName(), orderItem.getPrice(), orderItem.getCount(),
                orderItem.getTotalPrice(), orderItem.getOrderId());
    }

    @Override
    public List<OrderItem> queryOrderItemsById(String orderId) {
        String sql = "SELECT id,`name`,`price`, `count`, `total_price` totalPrice, " +
                "order_id orderId FROM order_item WHERE order_id = ?";
        return queryMulti(sql, OrderItem.class, orderId);
    }
}
